fix: filter temp-scoped state keys in SSE event generator#5203
Closed
surfai wants to merge 1 commit intogoogle:mainfrom
Closed
fix: filter temp-scoped state keys in SSE event generator#5203surfai wants to merge 1 commit intogoogle:mainfrom
surfai wants to merge 1 commit intogoogle:mainfrom
Conversation
Temp state keys (prefix `temp:`) can contain non-serializable objects such as `FunctionTool` instances stored by `_call_llm_node`. `_trim_temp_delta_state()` already filters these for persistence in `append_event()`, but the SSE event generator serializes events before they reach that path, causing `PydanticSerializationError` when `streaming=true`. Apply the same `State.TEMP_PREFIX` filtering in the SSE generator before `model_dump_json()`. Fixes #5051
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5051
Temp state keys (prefix
temp:) can contain non-serializable objects such asFunctionToolinstances stored by_call_llm_node._trim_temp_delta_state()already filters these for persistence inappend_event(), but the SSE event generator serializes events before they reach that path, causingPydanticSerializationErrorwhenstreaming=true.This PR applies the same
State.TEMP_PREFIXfiltering in the SSE generator beforemodel_dump_json().Root cause
_call_llm_node.py:131storesFunctionToolobjects inctx.state['temp:tools_dict']State.deltais a reference toevent_actions.state_delta— writes propagate immediatelybase_session_service.py:140(_trim_temp_delta_state) filterstemp:keys, but only insideappend_event()adk_web_server.py:1918serializes events viamodel_dump_json()beforeappend_event()—temp:keys with non-serializable values are still present → 💥Non-streaming (
/run) works because events pass through the fullappend_event()pipeline before serialization.Changes
src/google/adk/cli/adk_web_server.py— FilterState.TEMP_PREFIXkeys fromstate_deltain the SSE generator beforemodel_dump_json()(mirrors_trim_temp_delta_statelogic)tests/unittests/cli/test_fast_api.py— Regression test: event with non-serializabletemp:state keys streams successfully, non-temp keys are preservedTest plan
test_agent_run_sse_filters_temp_state_keysverifies:user_request) are preserved in the SSE outputtemp:tools_dict,temp:other) are stripped